package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.FilterConditionVO;
import com.cmc.cloud.cmclink.doc.vo.FilterFieldVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbadetailvo.VoyageBsaCbaDetailCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbadetailvo.VoyageBsaCbaDetailPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbadetailvo.VoyageBsaCbaDetailRespVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbadetailvo.VoyageBsaCbaDetailUpdateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsacbadetailvo.VoyageCbaDetailBatchVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.VoyageBsaCbaDetailDO;
import com.cmc.cloud.cmclink.doc.service.VoyageBsaCbaDetailService;


/**
 * 分类舱位自动批舱匹配条件前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 分类舱位自动批舱匹配条件")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/bsaCbaDetail")
public class VoyageBsaCbaDetailController {

    @Resource
    private VoyageBsaCbaDetailService voyageBsaCbaDetailService;

    @Operation(summary = "创建分类舱位自动批舱匹配条件")
    @PostMapping("/create")
    public CommonResult<Void> createVoyageBsaCbaDetail(@Valid @RequestBody VoyageBsaCbaDetailCreateReqVO createReqVO) {
        voyageBsaCbaDetailService.createVoyageBsaCbaDetail(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新分类舱位自动批舱匹配条件")
    @PostMapping("/update")
    public CommonResult<Void> updateVoyageBsaCbaDetail(@Valid @RequestBody VoyageBsaCbaDetailUpdateReqVO updateReqVO) {
        voyageBsaCbaDetailService.updateVoyageBsaCbaDetail(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除分类舱位自动批舱匹配条件")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteVoyageBsaCbaDetail(@PathVariable("id") Long id) {
        voyageBsaCbaDetailService.deleteVoyageBsaCbaDetail(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得分类舱位自动批舱匹配条件")
    @GetMapping("/getById/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBsaCbaDetailRespVO> getVoyageBsaCbaDetail(@PathVariable("id") Long id) {
        VoyageBsaCbaDetailDO voyageBsaCbaDetail = voyageBsaCbaDetailService.getVoyageBsaCbaDetail(id);
        return CommonResult.success(BeanUtil.copyProperties(voyageBsaCbaDetail, VoyageBsaCbaDetailRespVO.class));
    }

    @Operation(summary = "根据主信息id获取自动批舱匹配条件")
    @GetMapping("/getByMainId/{voyageBsaCbaId}")
    @Parameter(name = "voyageBsaCbaId", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBsaCbaDetailRespVO> getByMainId(@PathVariable("voyageBsaCbaId") Long voyageBsaCbaId) {
        return CommonResult.success(voyageBsaCbaDetailService.getByMainId(voyageBsaCbaId));
    }

    @Operation(summary = "获得分类舱位自动批舱匹配条件列表")
    @GetMapping("/listAll")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<VoyageBsaCbaDetailRespVO>> getVoyageBsaCbaDetailList(@RequestParam("ids") Collection<Long> ids) {
        List<VoyageBsaCbaDetailDO> list = voyageBsaCbaDetailService.getVoyageBsaCbaDetailList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VoyageBsaCbaDetailRespVO.class));
    }

    @Operation(summary = "获得分类舱位自动批舱匹配条件分页")
    @GetMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VoyageBsaCbaDetailRespVO>> getVoyageBsaCbaDetailPage(@Valid @RequestBody VoyageBsaCbaDetailPageReqVO pageVO) {
        PageResult<VoyageBsaCbaDetailDO> pageResult = voyageBsaCbaDetailService.getVoyageBsaCbaDetailPage(pageVO);
        List<VoyageBsaCbaDetailRespVO> results = BeanUtil.copyToList(pageResult.getList(), VoyageBsaCbaDetailRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }

    @Operation(summary = "批量 对分类舱位添加 条件过滤信息")
    @PostMapping("/batchCreate")
    public CommonResult<Void> batchSaveDetail(@Valid @RequestBody VoyageCbaDetailBatchVO detailBatchVO) {
        voyageBsaCbaDetailService.batchSaveDetail(detailBatchVO);
        return CommonResult.success();
    }

    @Operation(summary = "条件过滤字段信息")
    @GetMapping("/filterInfo")
    @Parameter(name = "enumType", description = "枚举名称", required = true, example = "")
    @Parameter(name = "keyWord", description = "字典名称模糊匹配字符", example = "")
    public CommonResult<List<FilterFieldVO>> getFilterInfo(@RequestParam("enumType") String enumType, @RequestParam(value = "keyWord", required = false) String keyWord) {
        List<FilterFieldVO> filterInfo = voyageBsaCbaDetailService.getFilterInfo(enumType, keyWord);
        return CommonResult.success(filterInfo);
    }

    @Operation(summary = "条件表达式信息")
    @GetMapping("/conditionInfo")
    @Parameter(name = "keyWord", description = "表达式描述中文", example = "")
    public CommonResult<List<FilterConditionVO>> conditionInfo(@RequestParam(value = "keyWord", required = false) String keyWord) {
        List<FilterConditionVO> filterConditionInfo = voyageBsaCbaDetailService.getFilterConditionInfo(keyWord);
        return CommonResult.success(filterConditionInfo);
    }
}
